<!-- 页面外套 -->
<div class="page-wrapper" id="personnel_attendance_overtime">
    
    <!-- 数据网格 -->
    <div class="datagrid datagrid-striped" id="personnel_attendance_overtime_datagrid">

        <!-- 工具条组 -->
        <div class="tool-group">
            <div class="tool-search">
                <div class="im-label">
                    <div class="input-group">
                        <select class="form-control" id="personnel_attendance_overtime_tool_keys">
                            <option value="1">姓名</option>
                            <option value="2">工号</option>
                        </select>
                        <span class="input-group-addon fix-border fix-padding"></span>
                        <input type="text" class="form-control" id="personnel_attendance_overtime_tool_search">
                    </div>
                </div>
                <label id="personnel_attendance_overtime_tool_select_group"><!--JS推进--></label>
                <label>
                    <span>加班类型：</span>
                    <select class="form-control" id="personnel_attendance_overtime_tool_select3"><!--JS推进--></select>
                </label>
                <label>
                    <span>补偿方式：</span>
                    <select class="form-control" id="personnel_attendance_overtime_tool_select4"><!--JS推进--></select>
                </label>
                <label><button class="btn btn-primary" id="personnel_attendance_overtime_search_btn"><i class="icon icon-search"></i> 搜索</button></label>
                <div class="clearfix"></div>
            </div>
            <div class="tool-deal">
                <label><button class="btn btn-primary" id="personnel_attendance_overtime_export_btn"><i class="icon icon-external-link"></i> 导出</button></label>
                <div class="clearfix"></div>
            </div>
        </div>
        <!-- tool-group -->

        <div class="datagrid-container"></div>
        <ul class="pager btn-mini" data-elements="prev,pages,next"></ul>
    </div>
    <!-- datagrid -->

</div>
<!-- page-wrapper -->

<script>
$(function(){

    //变量声明-----------------------------------------------------------------------------------------------
    var
    personnel_attendance_overtime                   = $("#personnel_attendance_overtime"),                  //页面ID
    personnel_attendance_overtime_datagrid          = $("#personnel_attendance_overtime_datagrid"),         //数据表格
    //搜索
    personnel_attendance_overtime_tool_keys         = $("#personnel_attendance_overtime_tool_keys"),        //搜索类别
    personnel_attendance_overtime_tool_search       = $("#personnel_attendance_overtime_tool_search"),      //搜索字段
    personnel_attendance_overtime_tool_select_group = $("#personnel_attendance_overtime_tool_select_group"),//下拉框组
    personnel_attendance_overtime_tool_select3      = $("#personnel_attendance_overtime_tool_select3"),     //下拉选择3
    personnel_attendance_overtime_tool_select4      = $("#personnel_attendance_overtime_tool_select4"),     //下拉选择4
    personnel_attendance_overtime_tool_date1        = $("#personnel_attendance_overtime_tool_date1"),       //开始时间
    personnel_attendance_overtime_tool_date2        = $("#personnel_attendance_overtime_tool_date2"),       //结束时间   
    personnel_attendance_overtime_search_btn        = $("#personnel_attendance_overtime_search_btn"),       //搜索按钮
    personnel_attendance_overtime_export_btn        = $("#personnel_attendance_overtime_export_btn");       //导出按钮

    //接口对象-----------------------------------------------------------------------------------------------
    if( window.STATE == "local" ){

        //本地接口
        var personnel_attendance_overtime_api  = {
            datagrid  : LOCAL + "Test/Personnel/Attendance/overtime.json",                                  //数据表格
            select    : LOCAL + "Test/test_select.json",                                                    //下拉选择
        }

    } else if ( window.STATE == "route" ){

        //远程接口
        var personnel_attendance_overtime_api  = {
            datagrid  : LOCAL + "Test/Personnel/Attendance/overtime.json",                                  //数据表格
            select    : LOCAL + "Test/test_select.json",                                                    //下拉选择
        }

    }

    //数据表格-----------------------------------------------------------------------------------------------
    personnel_attendance_overtime_datagrid.datagrid({
        height      : zui_datagrid_height(personnel_attendance_overtime_datagrid),
        sortable    : false,
        cache       : false,
        showRowIndex: true,
        configs     : {
            R0:{className:"text-center"},
            C1:{className:"cell-hidden"}
        },
        states      : {
            fixedLeftUntil  : 3,
            pager           : {
                page        : 1,
                recPerPage  : window.REC_PER_PAGE,
            }
        },
        dataSource : {
            cols   : [
                {width:49, name:"id",        label:"ID"      },
                {width:80, name:"user",      label:"姓名"    },
                {width:80, name:"numb",      label:"工号"    },
                {width:80, name:"depart",    label:"部门"    },
                {width:250,name:"date",      label:"加班日期"},
                {width:80, name:"duration",  label:"加班时长"},
                {width:100,name:"type",      label:"加班类型"},
                {width:80, name:"offset",    label:"补偿方式"},
            ],
            remote : function(){
                return {
                    url     : personnel_attendance_overtime_api.datagrid,
                    type    : "POST",
                    dataType: "json",
                }
            }
        }
    });//datagrid()

    //变量声明-----------------------------------------------------------------------------------------------
    var personnel_attendance_overtime_datagrid_obj = personnel_attendance_overtime_datagrid.data("zui.datagrid");//表格对象

    //下拉选项-----------------------------------------------------------------------------------------------
    common_select_linkage("#personnel_attendance_overtime_tool_select_group","1");                               //搜索
 
    //加班类型
    $.ajax({
        url     : personnel_attendance_overtime_api.select,
        type    : "post",
        dataType: "json",
        data    : {},
        success : function(data){
            if( data.status>0 ){
                var data = data.data;
                var option = "<option value='0'>全部</option>";
                for(var i=0;i<data.length;i++){
                    option += "<option value='"+data[i].id+"'>"+data[i].name+"</option>"
                }
                personnel_attendance_overtime_tool_select3.html(option);
            }
        }
    });

    //补偿方式
    $.ajax({
        url     : personnel_attendance_overtime_api.select,
        type    : "post",
        dataType: "json",
        data    : {},
        success : function(data){
            if( data.status>0 ){
                var data = data.data;
                var option = "<option value='0'>全部</option>";
                for(var i=0;i<data.length;i++){
                    option += "<option value='"+data[i].id+"'>"+data[i].name+"</option>"
                }
                personnel_attendance_overtime_tool_select4.html(option);
            }
        }
    });

    //搜索按钮-----------------------------------------------------------------------------------------------
    personnel_attendance_overtime_search_btn.click(function(){

        //字段整理
        var keyword
        = "?sid="    + personnel_attendance_overtime_tool_keys.val()
        + "&search=" + personnel_attendance_overtime_tool_search.val()
        + "&depart=" + personnel_attendance_overtime_tool_select_group.find(".common_select_depart").val()
        + "&type="   + personnel_attendance_overtime_tool_select3.val()
        + "&method=" + personnel_attendance_overtime_tool_select4.val();

        //GET提交
        zui_datagrid_render(personnel_attendance_overtime_datagrid_obj,personnel_attendance_overtime_api.datagrid+keyword);

    });

    //导出按钮-----------------------------------------------------------------------------------------------
    personnel_attendance_overtime_export_btn.click(function(){

        //远程提交
        $.ajax({
            url     : API.test_response,
            type    : "post",
            dataType: "json",
            data    : {
                keys    : personnel_attendance_overtime_tool_keys.val(),
                search  : personnel_attendance_overtime_tool_search.val(),
                depart  : personnel_attendance_overtime_tool_select_group.find(".common_select_depart").val(),
                type    : personnel_attendance_overtime_tool_select3.val(),
                method  : personnel_attendance_overtime_tool_select4.val(),
            },
            beforesend : function(){
                um_tip("导出中…");
            },
            success : function(data){
                if( data.status>0 ){
                    window.open(API.test_export);
                } else {
                    um_tip(data.message,"1500","text-danger");
                }
            }
        });

    });

});//预加载结尾
</script>